<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            position: relative;
            /* top: 0;
            left: 0; */
            width: 200px;
            height: 200px;
            background-color: skyblue;
            margin: 100px;
        }
    </style>
</head>

<body>
    <div class="box"></div>
    <script>
        let div = document.querySelector('div');
        div.addEventListener('mousedown', function(e) {

            let x = e.pageX - div.offsetLeft
            let y = e.pageY - div.offsetHeight
            div.innerHTML = 'x坐标' + x + 'y坐标' + y;
            document.addEventListener('mousemove', move);

            function move(e) {
                div.style.left = e.pageX - x + 'px';
                div.style.top = e.pageY - y + 'px';
            }
        })
    </script>
</body>

</html>